<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>分页界面</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
</head>
<body>
<div class="wrap-container clearfix">
    <div class="column-content-detail">
        <form class="layui-form">
            <div class="search-cont clearfix" id="tool">
                <div class="operation-btn-cont">
                    <div class="operright cyt-retract-close hideMenu"> 收起筛选<i class="iconfont">&#xe658;</i></div>
                    <div class="operright cyt-retract-open showMenu" style="display: none;"> 展开筛选<i class="iconfont">&#xe936;</i></div>
                    <!--button开始-->
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="addBtn"><i class="iconfont marr5">&#xe65e;</i>添加</button>
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="editBtn"><i class="iconfont marr5">&#xe606;</i>编辑</button>
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="deleteBtn"><i class="iconfont marr5">&#xe6a3;</i>删除</button>
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="releaseBtn"><i class="iconfont marr5">&#xe716;</i>发布</button>
                    <button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="unReleaseBtn"><i class="iconfont marr5">&#xe726;</i>取消发布</button>
                    <!--button结束-->
                    <div class="triangle-bottom"></div>
                    <div class="triangle-top"></div>
                </div>
                <div class="search-details">
                    <div class="layui-form-item marb5">
                        <!--search开始-->
                        <div class="layui-inline">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">类型：</label>
                            <div class="layui-input-inline">
                                <select name="bannerType" id="bannerType">
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">状态：</label>
                            <div class="layui-input-inline">
                                <select name="status" id="status">
                                </select>
                            </div>
                        </div>
                        <!--search结束-->
                        <div class="layui-inline marl8">
                            <button class="layui-btn layui-btn-normal" type="button" lay-submit="" lay-filter="seacherBtn">搜索</button>
                            <button class="layui-btn layui-btn-normal" type="reset">重置</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <div class="layui-form" id="table-list">
            <table id="entityList" lay-filter="entityList" class="cy-list-table"></table>
        </div>
    </div>
</div>
<!--操作-->
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    var applyId='${applyId}';
    var layer = null, tableIns = null;

    function show(path) {
        layer.open({
            type: 1
            , title: false
            , closeBtn: 0
            , skin: 'layui-layer-nobg'
            , shadeClose: true
            , content: '<img src="/sysFile/showFileByPath?path=' + path + '" style="max-height:300px;max-width:100%;">'
            , scrollbar: false
        })
    }

    layui.use(['jquery', 'table', 'layer', 'page', 'dialog', 'baseutil'], function () {
        var $ = layui.jquery,
            page = layui.page,
            table = layui.table,
            layer = layui.layer,
            dialog = layui.dialog,
            baseutil = layui.baseutil;

        //获取分页数据
        page.initDict('bannerType,releaseStatus', function (dictData) {
            page.showDict($("#bannerType"), page.aceeptDictContentList(dictData, 'bannerType'), "全部");
            page.showDict($("#status"), page.aceeptDictContentList(dictData, 'releaseStatus'), "全部");
            var url = "/work/site/banner/page?applyId="+applyId;
            var cols = [
                {type: 'checkbox', fixed: 'left'},
                {
                    field: 'path', title: '图片', align: 'center', templet: function (d) {
                        return "<img onclick='show(\"" + d.path + "\")' src='/sysFile/showFileByPath?path=" + d.path + "' style='width: 30px;height: 30px;'/>";
                    }
                },
                {field: 'title', title: '标题', align: 'center'},
                {
                    field: 'bannerType', title: '类型', align: 'center', templet: function (d) {
                        return page.aceeptDictContentName(dictData, 'bannerType', d.bannerType);
                    }
                },
                {field: 'orderNum', title: '排序', align: 'center'},
                {
                    field: 'status', title: '状态', align: 'center', templet: function (d) {
                        return page.aceeptDictContentName(dictData, 'releaseStatus', d.status);
                    }
                },
                {field: 'createUserName', title: '创建人', align: 'center'},
                {
                    field: 'createTime', title: '创建时间', align: 'center', templet: function (d) {
                        return new Date(d.createTime).Format("yyyy-MM-dd hh:mm");
                    }
                }
            ];
            tableIns = page.initDate(cols, url);
        });

        //监听添加按钮事件
        $('#addBtn').bind('click', function () {
            page.editPopup('/work/site/banner/getEdit?applyId='+applyId, '添加');
        });

        //监听编辑按钮事件
        $('#editBtn').bind('click', function () {
            var data = table.checkStatus('entityList').data;
            if (data.length === 0) {
                dialog.msg("请先选择轮播图");
                return false;
            } else if (data.length === 1) {
                if (data[0].status === '2') {
                    page.editPopup('/work/site/banner/getEdit?applyId='+applyId+'&id=' + data[0].id, '编辑');
                } else {
                    dialog.msg("请选择状态为未发布的轮播图");
                    return false;
                }
            } else if (data.length > 1) {
                dialog.msg("请选择单个轮播图");
                return false;
            }
        });

        //监听删除按钮事件
        $('#deleteBtn').bind('click', function () {
            var data = table.checkStatus('entityList').data;
            if (data.length === 0) {
                dialog.msg("请先选择轮播图");
                return false;
            } else {
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    if (data[i].status === '2') {
                        ids.push(data[i].id)
                    } else {
                        dialog.msg("只能删除状态为未发布的轮播图");
                        return false;
                    }
                }
                page.delete('/work/site/banner/remove', {"id": ids.join(","), "_method": "DELETE"}, "您确定要删除吗？", function () {
                    table.reload("entityList", {
                        where: {}
                    });
                });
            }
        });

        //监听发布按钮事件
        $('#releaseBtn').bind('click', function () {
            var data = table.checkStatus('entityList').data;
            if (data.length === 0) {
                dialog.msg("请先选择要发布的轮播图");
                return false;
            } else {
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    if (data[i].status === '2') {
                        ids.push(data[i].id)
                    } else {
                        dialog.msg("只能发布状态为未发布的轮播图");
                        return false;
                    }
                }
                baseutil.AjaxPostMark('/work/site/banner/updateStatus', {id: ids.join(","), status: '1'}, function () {
                    table.reload("entityList", {
                        where: {}
                    });
                });
            }
        });

        //监听取消发布按钮事件
        $('#unReleaseBtn').bind('click', function () {
            var data = table.checkStatus('entityList').data;
            if (data.length === 0) {
                dialog.msg("请先选择要取消发布的轮播图");
                return false;
            } else {
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    if (data[i].status === '1') {
                        ids.push(data[i].id)
                    } else {
                        dialog.msg("只能取消发布状态为已发布的轮播图");
                        return false;
                    }
                }
                baseutil.AjaxPostMark('/work/site/banner/updateStatus', {id: ids.join(","), status: '2'}, function () {
                    table.reload("entityList", {
                        where: {}
                    });
                });
            }
        });
    });
</script>
</body>
</html>